package com.kohler.blog.base.validator.constraint;

import com.kohler.blog.base.globalConf.Constants;
import com.kohler.blog.base.validator.annotation.IdValid;
import com.kohler.blog.utils.StringUtils;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * ID 校验器， 主要判断是否为空，且长度是否为32位
 */
public class IdValidator implements ConstraintValidator<IdValid, String> {

    @Override
    public void initialize(IdValid constraintAnnotation) {

    }

    @Override
    public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) {

        return !StringUtils.isBlank(value) && !StringUtils.isEmpty(value) && value.length() == Constants.THIRTY_TWO;
    }
}
